$(function () {
    let container = document.querySelector('#content>.content')
    fetch('http://chst.vip:1234/api/getcoupon')
        .then(body => body.json())
        .then(res => {
            let str = ''
            res.result.forEach(item => {
                let regExp = /(\/|http)[^>]+\.(jpg|jpeg|png|gif)/g;
                src = item.couponImg.match(regExp)
                str += `<div couponid=${item.couponId}>
            <img src=${src} alt="">
            <p>${item.couponTitle}</p>
        </div>`
            })
            container.innerHTML = str
            let divs = document.querySelectorAll('#content>.content>div')
            for (var i = 0; i < divs.length; i++) {
                divs[i].onclick = function () {
                    let id = $(this).attr('couponid')
                    location.href = './couponList.html?couponId=' + id
                }
            }
        })
})